home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Word8.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.1 KB  |  119 lines  |  [TEXT/R*ch]

  1. (* Word8 -- SML Standard Library *)
  2.  
  3. eqtype word
  4. val wordSize : int
  5.  
  6. val wordToInt  : word -> int
  7. val signExtend : word -> int
  8. val intToWord  : int -> word
  9.  
  10. val orb  : word * word -> word
  11. val andb : word * word -> word
  12. val xorb : word * word -> word
  13. val notb : word -> word
  14.  
  15. val <<  : word * Word.word -> word
  16. val >>  : word * Word.word -> word
  17. val ~>> : word * Word.word -> word
  18.  
  19. val +   : word * word -> word
  20. val -   : word * word -> word
  21. val *   : word * word -> word
  22. val div : word * word -> word
  23. val mod : word * word -> word
  24.  
  25. val >   : word * word -> bool
  26. val <   : word * word -> bool
  27. val >=  : word * word -> bool
  28. val <=  : word * word -> bool
  29. val compare : word * word -> ordering
  30.  
  31. val toString   : word -> string
  32. val fromString : string -> word option
  33. val scan : StringCvt.radix -> {getc : 'a -> (char * 'a) option} 
  34.            -> 'a -> (word * 'a) option
  35. val fmt  : StringCvt.radix -> word -> string
  36.  
  37. (* [word] is the type of 8-bit words, or 8-bit unsigned integers in
  38.    the range 0..255.
  39.  
  40.    [wordSize] is 8.
  41.  
  42.    [wordToInt w] returns the integer in the range 0..255 represented by w.
  43.  
  44.    [signExtend w] returns the signed integer (in the range ~128..127)
  45.    represented by w.
  46.  
  47.    [intToWord i] returns the word holding the 8 least significant bits of i.
  48.  
  49.    [orb(w1, w2)] returns the bitwise `or' of w1 and w2.
  50.  
  51.    [andb(w1, w2)] returns the bitwise `and' of w1 and w2.
  52.  
  53.    [xorb(w1, w2)] returns the bitwise `exclusive or' or w1 and w2.
  54.  
  55.    [notb w] returns the bitwise negation of w.
  56.  
  57.    [<<(w, k)] returns the word resulting from shifting w left by k
  58.    bits.  The bits shifted in are zero, so this is a logical shift.
  59.    Consequently, the result is 0-bits when k >= wordSize.
  60.  
  61.    [>>(w, k)] returns the word resulting from shifting w right by k
  62.    bits.  The bits shifted in are zero, so this is a logical shift.
  63.    Consequently, the result is 0-bits when k >= wordSize.
  64.  
  65.    [~>>(w, k)] returns the word resulting from shifting w right by k
  66.    bits.  The bits shifted in are replications of the left-most bit:
  67.    the `sign bit', so this is an arithmetical shift.  Consequently,
  68.    for k >= wordSize and wordToInt w >= 0 the result is all 0-bits, and 
  69.    for k >= wordSize and wordToInt w <  0 the result is all 1-bits.
  70.  
  71.    To make <<, >>, and ~>> infix, use the declaration 
  72.               infix 5 << >> ~>>
  73.  
  74.    [+, -, *, div, mod] represent unsigned integer addition,
  75.    subtraction, multiplication, division, and remainder, modulus 256.
  76.    The operations (i div j) and (i mod j) raise Div when j = 0.
  77.    Otherwise no exceptions are raised.
  78.  
  79.    [w1 > w2] returns true if the unsigned integer represented by w1
  80.    is larger than that of w2, and similarly for <, >=, <=.  
  81.  
  82.    [compare(w1, w2)] returns LESS, EQUAL, or GREATER, according 
  83.    as w1 is less than, equal to, or greater than w2 (as unsigned integers).
  84.  
  85.    [fmt radix w] returns a string representing w, in the radix (base)
  86.    specified by radix.
  87.  
  88.      radix    description                    
  89.      ---------------------------------------
  90.       BIN     unsigned binary      (base  2) 
  91.       OCT     unsigned octal       (base  8)   
  92.       DEC     unsigned decimal     (base 10)   
  93.       HEX     unsigned hexadecimal (base 16)   
  94.  
  95.    [toString w] returns a string representing w in unsigned
  96.    hexadecimal format.  Equivalent to (fmt HEX w).
  97.    
  98.    [fromString s] returns SOME(w) if a hexadecimal unsigned numeral
  99.    can be scanned from a prefix of string s, ignoring any initial
  100.    whitespace; returns NONE otherwise.  An unsigned hexadecimal
  101.    numeral must have form, after possible initial whitespace:
  102.        [0-9a-fA-F]+
  103.  
  104.    [scan radix {getc} charsrc] attempts to scan an unsigned numeral
  105.    from the character source charsrc, using the accessor getc, and
  106.    ignoring any initial whitespace.  The radix argument specifies the
  107.    base of the numeral (BIN, OCT, DEC, HEX).  If successful, it
  108.    returns SOME(w, rest) where w is the value of the numeral scanned,
  109.    and rest is the unused part of the character source.  A numeral
  110.    must have form, after possible initial whitespace:
  111.  
  112.      radix    format 
  113.      ---------------------
  114.       BIN     [0-1]+
  115.       OCT     [0-7]+
  116.       DEC     [0-9]+
  117.       HEX     [0-9a-fA-F]+
  118. *)
  119.